/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __PQ_MonoEngine_H__
#define __PQ_MonoEngine_H__

//using nono as our script engine
#include <mono/jit/jit.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/assembly.h>

#include "EnginePrerequisites.h"
#include "GameObjectSerializer.h"
//test 
//using namespace PQEngine;
//#include "mono/mono_engine.h"
/*
void testMonoEngine()
{
	GameObject* root=new GameObject("Root",NULL,true);
	GameObject* child1=new GameObject("child1");
	GameObject* child2=new GameObject("child2");
	GameObject* child3=new GameObject("child2");
	GameObject* child4=new GameObject("child2");

	root->addChild(child1);
	root->addChild(child2);
	child1->addChild(child3);
	child2->addChild(child4);
	MonoEngine::getSingleton().init(root);
}
*/

namespace PQEngine
{
	class MonoEngine
	{
	private:
		MonoDomain* _domain;
		MonoAssembly* _monoLibAssembly;
		MonoImage* _monoLibImage;//

		MonoClass *_monoEngineClass;//main class in mono space

		MonoMethod* _createGameObject;//host invoke method
		MonoMethod* _createComponent;
		MonoMethod* _createScript;
		MonoMethod* _attachComponent;
		MonoMethod* _addChildObject;
		MonoMethod* _updateMonoEngine;

		GameObjectSerializer* _gameObjectSerializer;
	protected:
		MonoEngine();
	public:
		~MonoEngine();
		static MonoEngine& getSingleton();
		void init(GameObject* root);
		void initMonoExecutor();
		void initRootGameObject(GameObject* root);

		void initMonoClasses();
		void initGameObjects();
		void addGameObject(GameObject* object);
		void addComponent(GameObject* object,Component* component);

		//in mono space
		void createMonoGameObject(GameObject* object);
		void createMonoComponent(Component* component);
		void addChildGameObject(int parentId,int childId);
		void addMonoComponent(int objectId,int componentId);

		bool createMesh(std::string name,int x,int y);

		void update(float deltaT);
	};

}

#endif
